import { request } from "../untils/request.js";
export default {
    get: ({ curPage, eachPage }) => request({
        type: "GET",
        url: "/api/movies",
        data: { curPage, eachPage },
    }),

    getOne: _id => request({
        type: "GET",
        url: `/api/movies/${_id}`,
    }),
      // 电影查询
    searchMove: (movie) => request({
        type: "POST",
        url: `/api/movies/findmovie`,
        data:{movie},
    }),
    add: movie => request({
        type: "POST",
        url: "/api/movies/add",
        data: movie,
    }),

    // 删除数据
    remove:async removeData=>{
        return await request({
            type:"POST",
            url:"/api/movies/remove",
            data:removeData,
        })
    },
    //    删除图片
     deleteImg: async ({ _id, url}) =>
     await request({
         type: "DELETE",
         // restful风格定义接口  encodeURIComponent将路径中的/做处理
         url: `/resource/movies/${_id}/imgs/${encodeURIComponent(url)}`,
     }),
    //  删除海报
    deletePoster: async ({ _id, url}) =>
    await request({
        type: "DELETE",
        // restful风格定义接口  encodeURIComponent将路径中的/做处理
        url: `/resource/movies/${_id}/imgs/${encodeURIComponent(url)}`,
    }),


    // 修改
    change: async (newData) => {
        return await request({
            type: "PUT",
            url: "/api/movies/change",
            data: newData,
        })
    },
   // 通过_id查找整条数据
    findOne: async _id =>
    await request({
        type: "GET",
        url: `/api/movies/findOne/${_id}`,
    }),


    // 获取所有电影数据  排片用的
    getall: () =>
        request({
            type: "GET",
            url: "/api/movies/moviesListAll",
        }),
}